package com.gdit.comm.config;
//
//import com.gdit.comm.security.*;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
//import org.springframework.security.config.annotation.web.builders.HttpSecurity;
//import org.springframework.security.config.annotation.web.builders.WebSecurity;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.config.http.SessionCreationPolicy;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//import javax.annotation.Resource;
//
///**
// * @author fgba
// */
//@Configuration
//@EnableGlobalMethodSecurity(prePostEnabled = true)
//@EnableWebSecurity
//public class SecurityConfig extends WebSecurityConfigurerAdapter {
//
//    @Resource
//    private LoginFailureHandler failureHandler;
//
//    @Resource
//    private LoginSuccessHandler successHandler;
//
//    @Resource
//    private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
//
//    @Resource
//    private JwtAccessDeniedHandler jwtAccessDeniedHandler;
//
//    @Resource
//    private UserDetailsServiceImpl userDetailsService;
//
//    @Resource
//    private JwtLogoutHandler jwtLogoutHandler;
//
//    @Bean
//    JwtAuthenticationFilter jwtAuthenticationFilter() throws Exception {
//        return new JwtAuthenticationFilter(authenticationManager());
//    }
//
//    @Bean
//    BCryptPasswordEncoder bCryptPasswordEncoder() {
//        return new BCryptPasswordEncoder();
//    }
//
//    public static final String[] URL_WHITELIST = {
//            "/favicon.ico",
//            "/login",
//            "/logout",
//    };
//
//    @Override
//    protected void configure(HttpSecurity http) throws Exception {
//        http.cors().and().csrf().disable()
//                //登录配置
//                .formLogin()
//                .successHandler(successHandler)
//                .failureHandler(failureHandler)
//                //登出配置
//                .and()
//                .logout()
//                .logoutSuccessHandler(jwtLogoutHandler)
//                .and()
//                .authorizeRequests()
//                .antMatchers(URL_WHITELIST).permitAll()
//                // 不会创建 session
//                .and()
//                .sessionManagement()
//                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
//                //拦截规则配置
//                .and()
//                .authorizeRequests()
//                .anyRequest().authenticated()
//                //异常处理器
//                .and()
//                .exceptionHandling()
//                .authenticationEntryPoint(jwtAuthenticationEntryPoint)
//                .accessDeniedHandler(jwtAccessDeniedHandler)
//                //配置自定义过滤器
//                .and()
//                // 登录校验过滤器
//                .addFilter(jwtAuthenticationFilter())
//        ;
//
//    }
//
//    @Override
//    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
//        auth.userDetailsService(userDetailsService);
//    }
//}
